package com.fzu.ess.sys.entity;

import com.fzu.ess.common.entity.BaseEntity;
import lombok.*;
import org.hibernate.annotations.*;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ercha on 2015/10/16.
 */
@Entity
@Getter @Setter @NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@DynamicInsert @DynamicUpdate
@Table(name = "sys_menu")
public class Menu extends BaseEntity {

    public Menu(String id){
        this.id = id;
    }

    @Column(name = "name")
    private String name;

    @Column(name = "remark")
    private String remark;

    @Column(name = "parent_id")
    private Integer parentId;

    @Column(name = "parent_ids")
    private String parentIds;

//    @Column(name = "left_num")
//    private Integer leftNum;
//
//    @Column(name = "right_num")
//    private Integer rightNum;

    @Column(name = "href")
    private String href;

    @Column(name = "permission")
    private String permission;

    //删除时，同时删除中间表数据，role 的数据不影响，同理 role 也是
    @ManyToMany(mappedBy = "menuList", fetch=FetchType.LAZY)
    //@OrderBy("id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    private List<Role> roleList = new ArrayList<>();


}
